/*
 * Copyright (c) 2011
 * UNPUBLISHED PROPRIETARY SOURCE CODE.
 */

package com.webservice.service;

import com.webservice.domain.User;
import com.webservice.exception.EmailAlreadyInUseException;
import com.webservice.exception.NicknameAlreadyInUseException;
import com.webservice.exception.TokenAlreadyInUseException;
import com.webservice.exception.user.InvalidPasswordException;
import com.webservice.exception.user.SignInNotFoundException;
import com.webservice.exception.user.UserNotFoundException;

/**
 * Service interface for working with {@link User}.
 *
 * @author vkolodrevskiy
 */
public interface IUserService {
    /**
     * Creates user.
     *
     * @param user user to create.
     * @return <code>User</code>
     * @throws EmailAlreadyInUseException if user with given email already exists.
     * @throws com.webservice.exception.NicknameAlreadyInUseException if user with given username already exists.
     * @throws com.webservice.exception.TokenAlreadyInUseException If token is already used.
     */
    User createUser(User user) throws NicknameAlreadyInUseException, EmailAlreadyInUseException, TokenAlreadyInUseException;

    /**
     * Updates user.
     *
     * @param user user to update.
     * @return <code>User</code>
     * @throws EmailAlreadyInUseException if user with given email already exists.
     * @throws com.webservice.exception.NicknameAlreadyInUseException if user with given username already exists.
     * @throws com.webservice.exception.user.UserNotFoundException if user with the given id was not found.
     */
    User updateUser(User user) throws NicknameAlreadyInUseException, EmailAlreadyInUseException, UserNotFoundException;

    /**
     * Authenticate a local member account via sign-in and password.
     *
     * @param signin the signin name; can either be an account username or email address
     * @param password the member's password of at least 6 characters
     * @return the authenticated Account, if authentication was successful
     * @throws SignInNotFoundException an Account could not be found with the provided signin name
     * @throws InvalidPasswordException the password was not valid
     */
    User login(String signin, String password) throws SignInNotFoundException, InvalidPasswordException;

    /**
     * Find user account with given unique identifier.
     * @param id id of the user account to find.
     * @return <code>User</code> with the given id.
     * @throws UserNotFoundException if user was not found.
     */
    User findUserById(long id) throws UserNotFoundException;

    /**
     * Find user account with given unique token.
     * @param token token of the user account to find.
     * @return <code>User</code> with the given id.
     * @throws UserNotFoundException if user was not found.
     */
    User findUserByToken(String token) throws UserNotFoundException;

    /**
     * Removes (aka sets active=false) user by token.
     * @param token unique token of user to remove.
     */
    void removeUserByToken(String token);
}
